package com.ztk.threadbasic.excel.handler;

import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.metadata.property.FontProperty;
import com.alibaba.excel.metadata.property.NumberFormatProperty;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy;
import org.apache.poi.ss.usermodel.*;

import java.math.RoundingMode;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 示例数据红色标记实现类
 */
public class ExampleDataRedColorHandler extends AbstractVerticalCellStyleStrategy {

    // 第一列中，字体需要加粗的行数
    private final List<Integer> first_column_bold = Arrays.asList(4, 20, 22, 26, 27, 34, 39);

    @Override
    protected WriteCellStyle contentCellStyle(CellWriteHandlerContext context) {

        Cell cell = context.getCell();
        int columnIndex = cell.getColumnIndex();
        int rowIndex = cell.getRowIndex();

        ExcelContentProperty excelContentProperty = context.getExcelContentProperty();
        FontProperty contentFontProperty = excelContentProperty.getContentFontProperty();

        if (columnIndex == 0 && first_column_bold.contains(rowIndex)) {
            if (contentFontProperty == null) {
                contentFontProperty = new FontProperty();
            }
            contentFontProperty.setBold(true);
        }

        return WriteCellStyle.build(excelContentProperty.getContentStyleProperty(), contentFontProperty);
    }
}

